/*
 * @Author: guoyangf
 * @Date: 2020-05-29 11:07:55
 * @LastEditTime: 2020-08-07 17:12:49
 * @Description: file content
 */
import React, { Component } from 'react';
import './index.less'

class ButtonGroupCtrl extends Component {
    static comName = 'ButtonGroup';


    constructor(props) {
        super();
        this.NCProps = window.__SSC_NCProps;
    }

    render() {

        const { button } = this.NCProps;
        return (
            <div className="button-group-ctrl">
                {this.props.isShowSagaIcon
                    &&
                    (
                        <span
                            className='error-flag iconfont icon icon-gantanhao'
                            onClick={ () => {
                                this.props.sagaIconClickEvent && this.props.sagaIconClickEvent();
                            }}>
                        </span>
                    )
                }

                {
                    button.createButtonApp({
                        area: this.props.btnTplArea,
                        buttonLimit: 3,
                        onButtonClick: async (_, key) => {
                            console.log('点击按钮的key', key);
                            if (this.props.btnEvent instanceof Promise) {
                                let btnEvent = await this.props.btnEvent;
                                if (btnEvent[key]) {
                                    let isExecClickEvent = null; //执行click事件
                                    let isExecAfterEvent = null; //执行after事件
                                    if (this.props.btnBeforeEvent) {
                                        isExecClickEvent = this.props.btnBeforeEvent()
                                    }
                                    isExecClickEvent !== false && (isExecAfterEvent = await btnEvent[key]());
                                    isExecAfterEvent !== false && this.props.btnAfterEvent && this.props.btnAfterEvent();
                                }
                            } else {
                                if (this.props.btnEvent && this.props.btnEvent[key]) {
                                    let isExecClickEvent = null; //执行click事件
                                    let isExecAfterEvent = null; //执行after事件
                                    if (this.props.btnBeforeEvent) {
                                        isExecClickEvent = this.props.btnBeforeEvent()
                                    }
                                    isExecClickEvent !== false && (isExecAfterEvent = this.props.btnEvent[key]());
                                    isExecAfterEvent !== false && this.props.btnAfterEvent && this.props.btnAfterEvent();
                                }


                            }
                        }
                    })
                }
                {/* <button>777</button> */}
            </div>
        )
    }
}

export default ButtonGroupCtrl
